package com.china08.yxyapi.api.manage.tec.teaching.live.handleLive;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.api.manage.tec.teaching.live.myClassSchedule.MyClassScheduleController;
import com.china08.yxyapi.model.YxyApiReqModel;

import io.swagger.annotations.ApiOperation;

/**
 * 我的教学-直播课-教师-教育局查询
 * @author 赵亚辉
 *
 */
@CrossOrigin
@RestController
public class EduOfficeFindController extends YxyApiBaseController{
	
	private static final Logger logger=Logger.getLogger(MyClassScheduleController.class);
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@ApiOperation(value = "直播课查询")
    @RequestMapping(value = "/api_yw/manage/tec/teaching/live/eduOffice/find", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel find(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
		
		RespModel respModel=new RespModel();
		
		List<Map<String, Object>> eduOfficeList=new ArrayList<>();
		
		String schoolId = getProfile(request, response).getSchoolId();
		
		String schooldSQL="select id,area_id_province,area_id_city,area_id_district from china08_yunxiao_pro.app_school"
				+ " where id='"+schoolId+"' and status=1 and is_bureau=0";
		List<Map<String, Object>> schoolMapList = jdbcTemplate.queryForList(schooldSQL);
		if(schoolMapList!=null&&schoolMapList.size()>0){
			Map<String, Object> schoolMap=schoolMapList.get(0);
			String areaIdProvince=(String) schoolMap.get("area_id_province");
			String areaIdCity=(String) schoolMap.get("area_id_city");
			String areaIdDistrict=(String) schoolMap.get("area_id_district");
			
			String eduOfficeCitySQL="select id,school_nick name from china08_yunxiao_pro.app_school"
					+ " where area_id_province='"+areaIdProvince+"' and area_id_city='"+areaIdCity
					+"' and status=1 and is_bureau=1 and bureau_level=1";
			String eduOfficeDistrictSQL="select id,school_nick name from china08_yunxiao_pro.app_school"
					+ " where area_id_province='"+areaIdProvince+"' and area_id_city='"+areaIdCity
					+"' and area_id_district='"+areaIdDistrict+"' and status=1 and is_bureau=1 and bureau_level=0";
			
			List<Map<String, Object>> cityMapList = jdbcTemplate.queryForList(eduOfficeCitySQL);
			List<Map<String, Object>> districtMapList = jdbcTemplate.queryForList(eduOfficeDistrictSQL);
			
			if(cityMapList.size()>0){
				Map<String, Object> cityMap=cityMapList.get(0);
				eduOfficeList.add(cityMap);
			}
			if(districtMapList.size()>0){
				Map<String, Object> districtMap=districtMapList.get(0);
				eduOfficeList.add(districtMap);
			}
		}
		
		respModel.eduOfficeList=eduOfficeList;
		
		return respModel;
	}
	
	protected static class ReqModel extends YxyApiReqModel{
		
	}
	
	protected static class RespModel {
		
		public List<Map<String, Object>> eduOfficeList;

	}
	

}
